define(['app'], function(app) {
    app.controller('MockUsersController', function($http, xDialog, toastr,$scope) {
        var self = this;
        self.users = [];
        var eamil='';

        self.init = function() {
            $http.get('/mock/user/getUserList').then(function(response) {
                self.users = response.data;
            });
        };
        self.updateUser=function (loginName,type) {

            if (type=='delete' )
            {
                xDialog.confirm('确认信息', '您确定要删除【' + loginName + '】用户？').then(function(yes) {
                    if (yes) {
                        $http.post('/mock/user/delete',{loginName:loginName}).then(function(response) {
                            if (response.data) {
                                toastr.success('【' + loginName + '】用户已删除！');
                                self.init();
                            }
                        });
                    }
                });

            }
            else if (type=='update' )
            {
                xDialog.confirm('确认信息', '您确定要把【' + loginName + '】设为管理员？').then(function(yes) {
                    if (yes) {

                         $http.post('/mock/user/update',{loginName:loginName}).then(function(response) {
                             if (response.data) {
                                 toastr.success('【' + loginName + '】用户已设置为管理员！');
                                 self.init();
                             }
                         });
                    }
                });
            }else {
                xDialog.confirm("警告信息",'操作失败请联系管理员!')
            }

        }



    });
});
